




def analyze(self):
    # 从 parameter_setting 中获取参数
    parameters = self.main_window.hyperparameter_data.get("parameter_setting", {})
    if isinstance(parameters, dict):
        try:
            # 提取两个个参数
            task_type = str(parameters.get("task_type")) if parameters.get("task_type") else None
            model_type = str(parameters.get("model_type")) if parameters.get("model_type") else None
        except Exception as e:
            print(f"Error extracting parameters: {e}")

    # 从 hyperparameter_data 中获取参数
    hyperparams0 = self.main_window.hyperparameter_data.get("Hyperparameter0", {})
    print(hyperparams0, "=====================")
    hyperparams1 = self.main_window.hyperparameter_data.get("Hyperparameter1", {})
    print(hyperparams1, "=====================")
    hyperparams2 = self.main_window.hyperparameter_data.get("Hyperparameter2", {})
    print(hyperparams2, "=====================")
    # 确保 hyperparams 是一个字典
    if isinstance(hyperparams0, dict):
        try:
            # 提取七个参数
            gb_param1 = float(hyperparams0.get("param1")) if hyperparams0.get("param1") else None
            gb_param2 = int(hyperparams0.get("param2")) if hyperparams0.get("param2") else None
            gb_param3 = float(hyperparams0.get("param3")) if hyperparams0.get("param3") else None
            gb_param4 = int(hyperparams0.get("param4")) if hyperparams0.get("param4") else None
            gb_param5 = int(hyperparams0.get("param5")) if hyperparams0.get("param5") else None
            gb_param6 = int(hyperparams0.get("param6")) if hyperparams0.get("param6") else None
            gb_param7 = int(hyperparams0.get("param7")) if hyperparams0.get("param7") else None
        except Exception as e:
            print(f"Error extracting parameters: {e}")
    else:
        print("Hyperparams is not a dictionary.")
        gb_param1, gb_param2, gb_param3, gb_param4, gb_param5, gb_param6, gb_param7 = [None] * 7  # 所有参数设置为 None

    if self.current_step == 3:
        self.update_step_labels()
        self.update_buttons()
        self.labelExperimentResult.setStyleSheet(f"background-color: #aaff00")
        try:
            model_results = gradient_boosting_main(
                task_type=task_type if task_type is not None else None,
                model_type=model_type if model_type is not None else None,
                test_size=gb_param1 if gb_param1 is not None else None,
                random_state=gb_param2 if gb_param2 is not None else None,
                learning_rate=gb_param3 if gb_param3 is not None else None,
                max_depth=gb_param4 if gb_param4 is not None else None,
                min_samples_leaf=gb_param5 if gb_param5 is not None else None,
                min_samples_split=gb_param6 if gb_param6 is not None else None,
                n_estimators=gb_param7 if gb_param7 is not None else None
            )

            # 打印模型结果
            print(json.dumps(model_results, ensure_ascii=False, indent=4))
            # 保存结果到主窗口对象
            self.main_window.model_results = model_results
            print("model_results is", self.main_window.model_results)
            if model_results is not None:
                # 实例化 ModelTableResultManager
                table_manager = ModelTableResultManager(self.main_window)
                table_manager.update_table(model_results)
        except Exception as e:
            print(f"Error while running gradient_boosting_main: {e}")
    if self.current_step == 6:
        self.update_step_labels()
        self.update_buttons()
        self.labelExperimentResult.setStyleSheet(f"background-color: #aaff00")
